<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>阻止事件冒泡</title>
    <style>
        .father{
            width: 300px;
            height: 300px;
            background-color: pink;
            margin: 40px auto;
        }
        .son{
            width: 200px;
            height: 200px;
            background-color: blueviolet;
            color: #fff;
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="father">
        <div class="son">son盒子</div>
    </div>

    <script>
       

       // 冒泡阶段  son---father---body---html---document
      //    阻止冒泡 dom 推荐的标准 stopPropagation()
       var son = document.querySelector('.son');
       son.addEventListener('click',function(e){
           alert('我是你爸爸');
           e.stopPropagation(); //阻止冒泡  stop 停止的意思  Propagation 传播的意思
           e.cancelBubble = true; //cancel 取消的意思 Bubble 泡泡   兼容性问题这个
        },false)
       var father = document.querySelector('.father');
       father.addEventListener('click',function(){
           alert('我是你爷爷');
       },false)
       document.addEventListener('click',function(){
           alert('你们都不是');
       })
    </script>
</body>
</html>